<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="工单编号" prop="number">
        <el-input v-model="queryParams.workNumber" placeholder="请输入工单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工单名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入工单名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工单类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择工单类型" class="width_100" @change="handleQuery">
          <el-option  v-for="item in orderTypeList"
                      :key="item.dictCode"
                      :label="item.dictValue"
                      :value="item.dictCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择工单状态" class="width_100" @change="handleQuery">
          <el-option v-for="item in orderStatusList" :key="item.key" :label="item.label" :value="item.key">
          </el-option>
        </el-select>
      </el-form-item>

      <!--<el-form-item label="计划完成时间" prop="planTime" label-width="100px">
        <el-date-picker clearable
          v-model="queryParams.planTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择计划完成时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="处理人" prop="dealPerson">
        <el-input
          v-model="queryParams.dealPerson"
          placeholder="请输入处理人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单来源" prop="origin">
        <el-input
          v-model="queryParams.origin"
          placeholder="请输入工单来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['workOrder:myOrder:add']" :disabled="dictCode == ''">新增</el-button>
      </el-col>
      <!--<el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['workOrder:myOrder:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['workOrder:myOrder:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['workOrder:myOrder:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="myOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="工单编号" align="center" prop="workNumber" width="140" />
<!--      <el-table-column label="项目代码" align="center" prop="projectCode" width="130" />-->
      <el-table-column label="工单名称" align="center" prop="name" />
      <el-table-column label="工单类型" align="center" prop="type" width="230">
        <template slot-scope="scope">
          <span>{{orderTypeObject[scope.row.type]}}</span>
        </template>
      </el-table-column>
<!--       <el-table-column label="工单内容" align="center" prop="contents" /> -->
      <el-table-column label="计划完成时间" align="center" prop="planTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理人" align="center" prop="dealPerson" width="80">
        <template slot-scope="scope">
          <span
            v-if="dealPersonList.indexOf(scope['row']['dealPerson']) != '-1'">{{personObject[scope.row.dealPerson]}}</span>
          <span v-else>{{scope.row.dealPerson}}</span>
        </template>
      </el-table-column>
<!--       <el-table-column label="处理记录" align="center" prop="dealLog" />-->
      <el-table-column label="状态" align="center" prop="status" width="140">
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.status == -1">创建中</el-tag>
          <el-tag type="primary" v-if="scope.row.status == 0">待处理</el-tag>
          <el-tag type="info" v-else-if="scope.row.status == 1">处理中</el-tag>
          <el-tag type="success" v-else-if="scope.row.status == 2">已完成</el-tag>
          <el-tag type="warning" v-else-if="scope.row.status == 3">已延期</el-tag>
          <el-tag type="danger" v-else-if="scope.row.status == 4">已关闭</el-tag>
        </template>
      </el-table-column>
<!--      <el-table-column label="工单来源" align="center" prop="origin" width="180"/>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="230px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="check(scope.row.id)">查看</el-button>
          <!--     <el-button
            v-if="scope.row.status == 0"
            size="mini"
            type="text"
            icon="el-icon-s-order"
            @click="acceptCase(scope.row.workNumber)"
          >受理</el-button>-->
          <el-button v-if="scope.row.status == -1" size="mini" type="text" icon="el-icon-s-order"
            @click="submit_(scope.row.workNumber)">提交</el-button>
          <!--(scope.row.status == 1 && scope.row.dealPerson == username)-->
          <el-button v-if=" (scope.row.status == -1)||(scope.row.status == 0)" size="mini" type="text"
            icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['workOrder:myOrder:edit']">修改</el-button>

          <!--    <el-button
            v-if="scope.row.status == 1 && scope.row.dealPerson == username"
            size="mini"
            type="text"
            icon="el-icon-share"
            @click="transfer(scope.row.id)"
          >转单</el-button>-->

          <!--      <el-button
            v-if="scope.row.status == 1 && scope.row.dealPerson == username"
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            @click="finish(scope.row.workNumber)"
          >完成</el-button>-->

          <el-button v-if=" scope.row.status == -1
            ||scope.row.status == 0" size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除
          </el-button>

         <!-- <el-button v-if="scope.row.status !=4" size="mini" type="text" icon="el-icon-circle-close"
            @click="close(scope.row.workNumber)">关闭</el-button>-->
          <!-- <el-button v-if="scope.row.status == -1 " size="mini" type="text" icon="el-icon-circle-close"
            @click="close(scope.row.workNumber)">关闭</el-button> -->
          <el-button v-if="scope.row.status ==2" size="mini" type="text" icon="el-icon-circle-close"
                     @click="disallowed(scope.row.id,scope.row.workNumber)">驳回</el-button>
          <el-button v-if="scope.row.status !=4" size="mini" type="text" icon="el-icon-circle-close"
            @click="closeOpen(scope.row.id,scope.row.workNumber)">关闭</el-button>
          <!-- <el-button v-if="scope.row.status == -1 " size="mini" type="text" icon="el-icon-circle-close"
            @click="close(scope.row.workNumber)">关闭</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改我的工单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body @close="cancel">
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">

        <el-form-item label="工单编号" prop="workNumber">
          <el-input v-model="form.workNumber" placeholder="请输入工单编号" :disabled="true" />
        </el-form-item>
        <el-form-item label="工单名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入工单名称" :disabled="checkDisabled" />
        </el-form-item>
        <el-form-item label="工单类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择工单类型" class="width_100" :disabled="checkDisabled">
            <el-option v-for="item in orderTypeList"
                       :key="item.dictCode"
                       :value="item.dictCode"
                       :label="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工单内容" prop="contents">
          <el-input v-model="form.contents" type="textarea" :autosize="{ minRows: 2, maxRows: 6}" placeholder="请输入内容" :disabled="checkDisabled" />
        </el-form-item>
        <el-form-item label="计划完成时间" prop="planTime">
          <el-date-picker clearable :disabled="checkDisabled" v-model="form.planTime" type="date"
            value-format="yyyy-MM-dd" style="width: 100%" placeholder="请选择计划完成时间">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="处理人" prop="dealPerson">
          <el-input v-model="form.dealPerson" placeholder="请输入处理人" />
        </el-form-item>-->
<!--        <el-form-item label="处理记录" prop="dealLog">-->
<!--          <el-input v-model="form.dealLog" type="textarea" :autosize="{ minRows: 6, maxRows: 6 }" placeholder="请输入内容" :disabled="checkDisabled"/>-->
<!--        </el-form-item>-->
        <!--<el-form-item label="工单来源" prop="origin">
          <el-input v-model="form.origin" placeholder="请输入工单来源" />
        </el-form-item>-->
        <el-form-item label="工单附件上传" prop="orderFile">
          <!-- 文件列表 -->
          <div class="upload-file-list el-upload-list el-upload-list--text">
            <div :key="file.url" class="el-upload-list__item ele-upload-list__item-content"
              v-for="(file, index) in fileList" style="display: flex;justify-content:  space-between">
              <el-link :underline="false" >
                <span class="el-icon-document" @click="downloadFile(file.url, file.name)"> {{ file.name }} </span>
              </el-link>
              <div class="ele-upload-list__item-content-action" v-if="!checkDisabled">
                <el-link v-if="form.id" :underline="false" @click="handleDeleteFile(file, index)" type="danger">删除</el-link>
                <el-link v-else :underline="false" @click="handleRemoveFile(file, index)" type="danger">删除</el-link>
              </div>
            </div>
          </div>
          <el-upload v-if="!checkDisabled" class="upload-demo" :headers="{Authorization: Authorization}"
            :action="uploadUrl" :data="{workNumber: form.workNumber, projectCode: currentProject}" name="file"
            :on-success="handleSuccess" :show-file-list="false" :file-list="fileList">
            <el-button size="small" type="primary">上传附件</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item v-if="form.id && checkDisabled" class="table-diy" label="工单流转记录" label-position="left" label-width="100px">
          <el-table v-if="checkDisabled" :data="form.orderLogs" style="width: 100%">
            <el-table-column prop="contents" align="center" label="处理操作" />
            <el-table-column prop="createTime" align="center" label="日期" width="100"/>
            <el-table-column prop="createBy" align="center" label="操作人" width="90"/>
            <el-table-column prop="remark" align="left" label="备注" width="150" />
          </el-table>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="type != 'view'&&flag">
          暂 存
        </el-button>
        <el-button type="success" @click="submitYesForm" v-if="type != 'view'">
          提 交
        </el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--转单-->
    <el-dialog title="转单" :visible.sync="transferVisible" width="500px" append-to-body>
      <el-form ref="transferForm" :model="transferForm" :rules="transferRules" label-width="130px">
        <el-form-item label="请选择接单人" prop="dealPerson">
          <el-select v-model="transferForm.dealPerson" placeholder="请选择接单人" class="width_100">
            <el-option v-for="item in transferList" :key="item.userName" :label="item.nickName" :value="item.userName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="transferForm.remark" type="textarea" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTransferForm">确 定</el-button>
        <el-button @click="transferVisible = false">取 消</el-button>
      </div>
    </el-dialog>


    <!--关闭工单-->
    <el-dialog title="关闭工单" :visible.sync="closeVisible" width="500px" append-to-body>
      <el-form ref="closeForm" :model="closeForm" :rules="closeRules" label-width="130px">
        <el-form-item label="备注" prop="remark">
          <el-input v-model="closeForm.remark" type="textarea" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="close">确 定</el-button>
        <el-button @click="closeVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <!--驳回工单-->
    <el-dialog title="驳回工单" :visible.sync="disallowedVisible" width="500px" append-to-body>
      <el-form ref="disallowedForm" :model="disallowedForm" :rules="closeRules" label-width="130px">
        <el-form-item label="备注" prop="remark">
          <el-input v-model="disallowedForm.remark" type="textarea" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="disallowedOrder()">确 定</el-button>
        <el-button @click="disallowedVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listMyOrder,
  getMyOrder,
  delMyOrder,
  addMyOrder,
  updateMyOrder,
  pickupPersonList,
  transferSure,
  finishMyOrder,
  closeMyOrder,
  submitOrder,
  acceptCaseOrder,
  getOrderNumber,
  orderDetail,
  disallowedMyOrder
} from "@/api/workOrder/myOrder";
import { delOrderEnclosure } from '@/api/workOrder/orderEnclosure';
import { getDicts } from '@/api/system/dict/data';
  import {
    getToken
  } from '@/utils/auth';

  export default {
    name: "MyOrder",
    data() {
      return {
        id: '',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 我的工单表格数据
        myOrderList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          number: null,
          projectCode: null,
          name: null,
          type: null,
          contents: null,
          planTime: null,
          dealPerson: null,
          dealLog: null,
          status: null,
          origin: null,
        },
        // 表单参数
        form: {
          workNumber: ''
        },
        // 表单校验
        rules: {
          workNumber: [{
              required: true,
              message: "",
              trigger: "blur"
            },

            // { min: 2, max: 20, message: '用户名称长度必须介于 2 和 20 之间', trigger: 'blur' }
          ],
          name: [{
            required: true,
            message: "工单名称不能为空",
            trigger: "blur"
          }, ],
          type: [{
            required: true,
            message: "工单类型不能为空",
            trigger: "change"
          }, ],
          contents: [{
            required: true,
            message: "工单内容不能为空",
            trigger: "blur"
          }, ],
        },
        orderTypeList: [
/*          {
            key: '0',
            label: '项目运维工单'
          },
          {
            key: '1',
            label: '系统工单'
          },
          {
            key: '2',
            label: '设备更换工单'
          },
          {
            key: '3',
            label: '需求工单'
          }*/
        ],
        orderTypeObject: {},
        orderStatusList: [{
            key: '-1',
            label: '创建中'
          },
          {
            key: '0',
            label: '待处理'
          },
          {
            key: '1',
            label: '处理中'
          },
          {
            key: '2',
            label: '已完成'
          },
          {
            key: '3',
            label: '已延期'
          },
          {
            key: '4',
            label: '已关闭'
          }
        ],
        flag:true,
        Authorization: 'Bearer ' + getToken(),
        checkDisabled: false,
        uploadUrl: process.env.VUE_APP_BASE_API + '/common/uploadWorkOrderFile',
        type: 'add',
        editDisabled: false,
        username: '',
        //关闭工单
        closeVisible:false,
        disallowedVisible:false,
        closeForm: {},
        disallowedForm: {},
        closeRules:{

        },
        transferForm: {},
        transferVisible: false,
        transferRules: {
          dealPerson: [{
            required: true,
            message: '请选择接单人',
            trigger: 'change'
          }],
        },
        transferList: [],
        personObject: {},
        dealPersonList: [],
        fileList: [],
        fileProcessList: [],
        dictCode: ''
      };
    },
    props: ['currentProject'],
    mounted() {
      this.getList();
      this.getPersonList();
      this.username = this.$store.state.user.name;
      this.getWorkerNumberDict();
      this.getOrderTypeList();
    },
    methods: {
      downloadFile(url, fileName) {
      const xhr = new XMLHttpRequest();
      xhr.open('GET', url, true);
      xhr.responseType = 'blob';

      xhr.onload = function() {
        if (xhr.status === 200) {
          const blob = new Blob([xhr.response], { type: 'application/octet-stream' });
          const downloadUrl = URL.createObjectURL(blob);

          const link = document.createElement('a');
          link.href = downloadUrl;
          link.download = fileName;
          link.click();

          URL.revokeObjectURL(downloadUrl);
        }
      };

      xhr.send();
    },
      getYzm() {
        let str = "qwertyuioplkjhgfdsazxcvbnm1234567890";
        let Yzm = "";
        for (let i = 0; i <= 3; i++) {
          let item = parseInt(Math.random() * (str.length - 1 + 0 + 1) - 0);
          Yzm += str[item];
        }
        return Yzm;
      },
      getWorkerNumberDict() {
        getOrderNumber(this.currentProject).then(res => {
          if (res.data != null) {
            this.dictCode = res.data;
          } else {
            this.$message.warning('该项目暂未配置编码规则, 请配置后在进行操作。');
          }
        });
      },
      getWorkNumber() {
        let workNumber = this.currentProject + '-' + this.dictCode + '-';
        let date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let strDate = date.getDate();
        workNumber += String(year) + String(month > 10 ? month : '0' + month) + String(strDate) + '-' + this.getYzm();
        this.form.workNumber = workNumber;
      },
      transformTypeObject() {
        let map = new Map();
        this.orderTypeList.forEach((d) => {
          map.set(d.dictCode, d.dictValue);
        });
        this.orderTypeObject = Object.fromEntries(map);
      },
      getOrderTypeList(){
        let oderTypeName = this.currentProject+"_gdlx";
        console.log(oderTypeName)
        getDicts(oderTypeName).then(response => {
          this.orderTypeList= response.data;
          this.transformTypeObject();
        })
      },
      /** 查询我的工单列表 */
      getList() {
        this.loading = true;
        this.queryParams.projectCode = this.currentProject;
        listMyOrder(this.queryParams).then(response => {
          this.myOrderList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
        this.resetList();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          number: null,
          projectCode: null,
          name: null,
          type: null,
          contents: null,
          planTime: null,
          dealPerson: null,
          dealLog: null,
          status: null,
          origin: '手动创建',
          createTime: null,
          createBy: null,
          updateTime: null,
          updateBy: null,
          orderEnclosureList: [],
          workNumber: ''
        };
        this.resetForm("form");
        this.checkDisabled = false;
        this.editDisabled = false;
      },
      resetList() {
        this.fileList = []
        this.fileProcessList = []
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.flag=true
        this.reset();
        this.open = true;
        this.type = 'add';
        this.title = "添加我的工单";
        this.getWorkNumber();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        orderDetail(id).then(response => {

          // console.log("调用查看方法,调用接口返回的数据为:",response)
          this.form = response.data;
          if( this.form.status==0){
            this.flag=false
          }else {
            this.flag=true
          }

          for (const oderType of this.orderTypeList) {
            if (this.form.type==oderType.dictCode){
              this.form.type=oderType.dictValue;
              break;
            }
          }

          if (this.form.orderEnclosureList != null && this.form.orderEnclosureList.length > 0) {
            let files = [];
            let processFiles = [];
            this.form.orderEnclosureList.forEach((d) => {
              if(d.type == 1) {
                files.push(d);
              }else if(d.type != 0) {
                processFiles.push(d);
              }
            });
            this.fileList = files;
            this.fileProcessList = processFiles;
          }
          // 根据工单编号 查询工单下的附件信息
          this.open = true;
          this.type = 'edit';
          this.title = "修改我的工单";
          this.editDisabled = true;
        });

      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.form.projectCode = this.currentProject;
            this.form.orderEnclosureList = this.fileList.concat(this.fileProcessList);
            if (this.form.id != null) {
              updateMyOrder(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
                this.resetList();
              });
            } else {
              this.form.status='-1'
              addMyOrder(this.form).then(response => {
                this.$modal.msgSuccess("暂存成功");
                this.open = false;
                this.getList();
                this.resetList();
              });
            }
          }
        });
      },
      getKeyByValue(value) {
        return Object.keys(this.orderTypeObject).find(key => this.orderTypeObject[key] === value);
      },
      /** 提交按钮 */
      submitYesForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            let form2={}
            this.form.projectCode = this.currentProject;
            this.form.orderEnclosureList = this.fileList.concat(this.fileProcessList);
            if (this.form.id != null) {
              this.form.status='0'
              form2 = Object.assign({}, this.form);
              if(!(typeof this.form.type === 'number')){
                form2.type = this.getKeyByValue(this.form.type)
              }
              updateMyOrder(form2).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
                this.resetList();
              });
            } else {
              this.form.status='0'
              addMyOrder(this.form).then(response => {
                this.$modal.msgSuccess("提交成功");
                this.open = false;
                this.getList();
                this.resetList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('删除后将同步删除工单内附件，确认删除？').then(function() {
          return delMyOrder(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('workOrder/myOrder/export', {
          ...this.queryParams
        }, `myOrder_${new Date().getTime()}.xlsx`)
      },
      handleRemoveFile(file, index) {
        // console.log(file.id)
        this.$modal.confirm('删除工单内当前工单附件，确认删除？').then(res => {
          this.fileList.splice(index, 1);
        })
      },
      handleProcessRemove(file, index) {
        this.$modal.confirm('删除工单内当前处理过程附件，确认删除？').then(res => {
            this.fileProcessList.splice(index, 1);
        })
      },
      // 删除文件
      handleDeleteFile(file, index) {
        // console.log(file.id)
        this.$modal.confirm('删除工单内当前工单附件，确认删除？').then(res => { // todo 根据当前工单id 删除当前工单附件
          delOrderEnclosure(file.id).then(res => {
            this.fileList.splice(index, 1);
            this.$modal.msgSuccess("删除成功");
          })
        })
      },
      // 删除文件
      handleProcessDelete(file, index) {
        this.$modal.confirm('删除工单内当前处理过程附件，确认删除？').then(res => {
          delOrderEnclosure(file.id).then(res => {
            this.fileProcessList.splice(index, 1);
            this.$modal.msgSuccess("删除成功");
          })
        })
      },

      //工单附件上传
      handleSuccess(res, file) {
        if (res.code == 200) {
          this.fileList.push({
            name: res.originalFilename,
            workNumber: this.form.workNumber,
            // type: 0,
            type: 1,
            url: res.url
          });

          //this.fileList = this.fileList.concat(this.form.orderEnclosureList);
        } else {

        }
      },
      //处理过程附件上传
      processHandleSuccess(res, file) {
        // console.log(res)
        if (res.code == 200) {
          this.fileProcessList.push({
            name: res.originalFilename,
            workNumber: this.form.workNumber,
            type: this.checkFileType(res.originalFilename),
            url: res.url
          });
          //console.log('this.fileProcessList', this.fileProcessList)
          //this.fileProcessList = this.fileProcessList.concat(this.form.orderEnclosureList);
        }
      },
      // 验证文件类型
      checkFileType(fileName) {
        const extension = fileName.split('.').pop().toLowerCase();
        switch (extension) {
          case 'jpg':
          case 'jpeg':
          case 'png':
          case 'gif':
            return 2; // 图片类型，返回数字2
          case 'pdf':
          case 'doc':
          case 'docx':
          case 'txt':
          return 3; // 文档类型，返回数字3
          default:
            return 4; // 其他类型，返回数字4
        }
      },
      //查看
      check(id) {
        // 根据工单id获取工单信息
        orderDetail(id).then(response => {
          this.form.type = response.data.type
          this.form = response.data;
          for (const oderType of this.orderTypeList) {
            if (this.form.type==oderType.dictCode){
              this.form.type=oderType.dictValue;
              break;
            }
          }
          if (this.form.orderEnclosureList != null && this.form.orderEnclosureList.length > 0) {
            let files = [];
            let processFiles = [];
            this.form.orderEnclosureList.forEach((d) => {
              if(d.type == 1) {
                  files.push(d);
              }else if(d.type != 0) {
                  processFiles.push(d);
              }
            });
            this.fileList = files;
            this.fileProcessList = processFiles;
          }
          // 根据工单编号 查询工单下的附件信息
          this.open = true;
          this.type = 'view';
          this.title = "查看我的工单";
          this.checkDisabled = true;
        });
      },
      //受理
      acceptCase(number) {
        acceptCaseOrder({
          workNumber: number
        }).then(res => {
          if (res.code == 200) {
            this.getList();
            this.$modal.msgSuccess("受理工单成功");
          }
        });
      },
      //提交
      submit_(number) {
        submitOrder({
          workNumber: number
        }).then(res => {
          if (res.code == 200) {
            this.getList();
            this.$modal.msgSuccess("提交工单成功");
          }
        });
      },
      getPersonList() {
        if (this.currentProject != '') {
          pickupPersonList(this.currentProject).then(res => {
            if (res.code == 200) {
              let map = new Map();
              res['data'].forEach((d) => {
                map.set(d.userName, d.nickName);
              });
              this.personObject = Object.fromEntries(map);
              this.transferList = res.data;
              this.dealPersonList = Object.keys(this.personObject);
            }
          });
        }
      },
      //转单
      transfer(id) {
        this.transferVisible = true;
        this.id = id;
      },
      //转单确认
      submitTransferForm() {
        this.$refs['transferForm'].validate((valid) => {
          if (valid) {
            this.transferForm.id = this.id;
            this.transferForm.workNumber = this.form.workNumber;
            console.log("传递的from为", this.transferForm)
            transferSure(this.transferForm).then(res => {
              if (res.code == 200) {
                this.$modal.msgSuccess("转单成功");
                this.getList();
                this.transferVisible = false;
              }
            })
        }
      });
    },
    //完成
    finish(number) {
        this.$confirm('确认完成该工单？', '完成提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          finishMyOrder({
            workNumber: number
          }).then(res => {
            if (res.code == 200) {
              this.getList();
              this.$modal.msgSuccess("完成工单成功");
            }
          });
        });
      },
      // 驳回备注输入框
      disallowed(id, workNumber) {
        // 根据这个id 查找对应 worknumber
        // 将查找到res.data.workNumber 赋值 然后载请求
        this.form.workNumber = workNumber;
        this.disallowedVisible = true;
        this.id = id;
      },
      disallowedOrder(){
        this.$refs['disallowedForm'].validate((valid) => {
          if (valid) {
            this.disallowedForm.id = this.id;
            this.disallowedForm.workNumber = this.form.workNumber;
            console.log("传递的from为", this.closeForm)
            disallowedMyOrder({
              workNumber: this.disallowedForm.workNumber,
              remark : this.disallowedForm.remark
            }).then(res => {
              if (res.code == 200) {
                this.disallowedVisible = false;
                this.closeForm.remark = '';
                this.getList();
                this.$modal.msgSuccess("驳回工单成功");
              }
            });
            // this.$confirm('确认关闭该工单？', '关闭提示', {
            //   confirmButtonText: '确定',
            //   cancelButtonText: '取消',
            //   type: 'warning'
            // }).then(() => {

            // });
          }
        });
      },
      //关闭输入框
      closeOpen(id, workNumber) {
        // 根据这个id 查找对应 worknumber
        // 将查找到res.data.workNumber 赋值 然后载请求
        this.form.workNumber = workNumber;
        this.closeVisible = true;
        this.id = id;
      },
      close(){
        this.$refs['closeForm'].validate((valid) => {
          if (valid) {
            this.closeForm.id = this.id;
            this.closeForm.workNumber = this.form.workNumber;
            console.log("传递的from为", this.closeForm)
            closeMyOrder({
                workNumber: this.closeForm.workNumber,
                remark : this.closeForm.remark
              }).then(res => {
                if (res.code == 200) {
                  this.closeVisible = false;
                  this.closeForm.remark = '';
                  this.getList();
                  this.$modal.msgSuccess("关闭工单成功");
                }
              });
            // this.$confirm('确认关闭该工单？', '关闭提示', {
            //   confirmButtonText: '确定',
            //   cancelButtonText: '取消',
            //   type: 'warning'
            // }).then(() => {

            // });
          }
        });
      },
      //关闭
   /*   close(number) {
        this.$confirm('确认关闭该工单？', '关闭提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          closeMyOrder({
            workNumber: number
          }).then(res => {
            if (res.code == 200) {
              this.getList();
              this.$modal.msgSuccess("关闭工单成功");
            }
          });
        });
      }*/
    }
  };
</script>

<style scoped>
  .width_100 {
    width: 100%;
  }
  ::v-deep .table-diy .el-form-item__content  {
    margin-left: 0 !important;
    margin-top: 10px;
  }
</style>
